﻿using StoryTeller.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.Validation;

namespace StoryTeller.Infrastructure.DataAccess.DAL.Base
{
    public class BaseDAL
    {
        private StoryTellerEntities _Entities;
        public StoryTellerEntities Entities
        {
            get
            {
                if (_Entities == null)
                {
                    _Entities =  new StoryTellerEntities();
                    _Entities.Database.Connection.Open();
                }
                return _Entities;
            }
        }

        public void Save()
        {
            try
            {
                Entities.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                throw ex;
            }
        }
    }
}
